'''
关键字驱动练习
'''
import time

from selenium import webdriver


class KeywordDemo:
    def __init__(self, browser_type, url):
        self.browser_init(browser_type)
        self.visit(url)

    def browser_init(self, browser_type):
        if browser_type == 'Chrome':
            self.driver = webdriver.Chrome()
            return self.driver
        if browser_type == 'ff':
            self.driver = webdriver.Firefox()
            return self.driver
        else:
            self.driver = webdriver.Ie()
            return self.driver

    def visit(self,url):
        self.driver.get(url)

    # 定位元素
    def locator(self, ids):
        el = self.driver.find_element_by_id(ids)
        return el

    def input_text(self,value):
        self.locator().send_keys(value)

    def click(self,ids):
        self.locator(ids).click()

    def close(self):
        self.driver.quit()


if __name__ == '__main__':
    url = "http://www.baidu.com"
    kd = KeywordDemo('Chrome', url)
    time.sleep(2)
    kd.close()